const { app, BrowserWindow, BrowserView, ipcMain } = require('electron')

const path = require('path')
function createWindow() {
  const editorWindow = new BrowserWindow({
    width: 1400,
    height: 1000,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
      // preload: path.join(__dirname, 'preload.js')
    }
  })

  editorWindow.loadURL('http://localhost:8080/editor.html');
  const runtimeView = new BrowserView()
  editorWindow.setBrowserView(runtimeView)
  runtimeView.setBounds({ x: 206, y: 2, width: 600, height: 600 })
  runtimeView.webContents.loadURL('http://localhost:8080/index.html?mode=edit');
  //runtimeView.webContents.openDevTools();
  editorWindow.webContents.openDevTools()
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})